import { Dimensions, PixelRatio } from 'react-native';

const { width, height } = Dimensions.get('window');

console.log(`width:${width}|height:${height}|ratio:${PixelRatio.get()}`);

export const deviceWidth = Dimensions.get('window').width; // 设备的宽度
export const deviceHeight = Dimensions.get('window').height; // 设备的高度

// const fontScale = PixelRatio.getFontScale();

const defaultPixel = 2; // iphone6的像素密度
// px转换成dp
const w2 = 720 / defaultPixel;
const h2 = 1280 / defaultPixel;
const scale = Math.min(deviceHeight / h2, deviceWidth / w2); // 获取缩放比例


export const Px2Dp = (size) => {
  const newSize = Math.round(size * scale + 0.5);
  return newSize / defaultPixel;
};

export const FontSize = (size) => {
  const newSize = Math.round((size * scale + 0.5));
  return newSize / defaultPixel * 1;
};
